<template>
    <view class="lazy-image">
        <img class="real-image" @load="onLoaded" :src="realSrc"/>
        <view :class="loaded ? 'loaded' : ''"><img :src="placeholdSrc"/></view>
    </view>
</template>

<script>
    export default {
        props: {
            placeholdSrc: {
                type: String,
                default: '../../static/img/img-sologon.png'
            },
            realSrc: {
                type: String,
                default: ''
            }
        },
        data() {
            return {
                loaded: false
            };
        },
        methods: {
            onLoaded() {
                this.loaded = true;
            }
        }
    };
</script>

<style lang="scss" scoped>
    .lazy-image {
        height: 100%;
        /* min-height: 370px; */
        /* height: 370px; */
        width: 100%;
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        position: relative;

        img {
            width: 100%;
            height: 100%;
            /* min-height: 370px; */
        }

        view {
            background-color: #eee;
            position: absolute;
            z-index: 2;
            top: 0;
            left: 0;
            height: 100%;
            width: 100%;
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            transition: opacity 0.4s linear;

            img {
                width: 100%;
            }
        }

        .loaded {
            opacity: 0;
        }
    }
</style>
